﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;

/// <summary>
/// MyRoleProvider 的摘要描述
/// </summary>
public class MyRoleProvider :RoleProvider
{
	public MyRoleProvider()
	{
		//
		// TODO: 在此加入建構函式的程式碼
		//
	}

    public override void AddUsersToRoles(string[] usernames, string[] roleNames)
    {
        throw new NotImplementedException();
    }

    public override string ApplicationName
    {
        get
        {
            throw new NotImplementedException();
        }
        set
        {
            throw new NotImplementedException();
        }
    }

    public override void CreateRole(string roleName)
    {
        throw new NotImplementedException();
    }

    public override bool DeleteRole(string roleName, bool throwOnPopulatedRole)
    {
        throw new NotImplementedException();
    }

    public override string[] FindUsersInRole(string roleName, string usernameToMatch)
    {
        throw new NotImplementedException();
    }

    public override string[] GetAllRoles()
    {
        throw new NotImplementedException();
    }

    public override string[] GetRolesForUser(string username)
    {
        var db = new DB();
        
        var result = db.ExecuteListScalar<string>(@"SELECT r.RoleID FROM Role r INNER JOIN RoleUserMap ru ON r.RoleID = ru.RoleID
                                WHERE ru.EmpID = @EmpID", new DBParameter("EmpID", EmpManager.Current.EmpID));

        if (EmpManager.Current.UserName != string.Empty)
        {
            result.Add("User"); //User
        }

        result.Add("Guest"); //Guest

        return result.ToArray();
    }

    public override string[] GetUsersInRole(string roleName)
    {
        throw new NotImplementedException();
    }

    public override bool IsUserInRole(string username, string roleName)
    {
        throw new NotImplementedException();
    }

    public override void RemoveUsersFromRoles(string[] usernames, string[] roleNames)
    {
        throw new NotImplementedException();
    }

    public override bool RoleExists(string roleName)
    {
        throw new NotImplementedException();
    }
}